home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / util2 / zgrep30.zip / REGEXP.TXT next >
Text File  |  1990-03-23  |  3KB  |  77 lines

  1. The Use of UNIX Regular Expressions
  2.  
  3. Regular Expressions are a standard function of the UNIX operating system.
  4. They are used to search for or replace text located within files or from the
  5. keyboard. The UNIX commands GREP (Global Regular Expression Print) and
  6. SUBS (SUBstitue Strings) are used to manipulate text via regular expressions.
  7.  
  8. There are various characters that the reuglar expression processor sees as
  9. having special meaning. These special characters are:
  10.  
  11. .       period      matches any alpha-numeric character
  12.  
  13. ^       caret       matches the beginning of the line
  14.                           zgrep ^#include
  15.                     will find all line beginning with #include
  16.  
  17. $       dollar      matches the end of the line
  18.                           zgrep }$
  19.                     will find all lines ending with a close brace
  20.  
  21. *       asterisk    Repeats any number of the last pattern. Includes
  22.                     zero repetitions.
  23.                           zgrep  test*
  24.                     finds lines with at least one occurence of test.
  25.  
  26. []      brakets     specifies a set of given characters.
  27.                           zgrep ^[abcd0123]
  28.                     will find lines begining with any one of the
  29.                     specified characters.
  30.  
  31. -       hyphen      denotes a range of characters.
  32.                           zgrep [A-Z0-9]$
  33.                     finds lines ending in a capital letter or a number.
  34.  
  35. \       backslash   removes the special characteristics of a character.
  36.                           zgrep \$
  37.                     finds dollar signs in a line of text.
  38.                           zgrep ^[A-D].*\.C$
  39.                     will locate all .C files that begin with the letters
  40.                     A through D.  Notice the escaping of the '.' before
  41.                     the C extent.
  42.  
  43. ,       comma       separates multiple reglar expressions
  44.                           zgrep ^[A-D],EXE$
  45.  
  46.                     will locate all files that begin with the letters
  47.                     A through D and All files that end in EXE.
  48.  
  49. NOTE:   When the caret (^) is used as the first character after a left
  50.         square braket, it reverses the meaning of the search.
  51.                 zgrep [^A-Z]&
  52.         will find all lines not ending with a capital letter.
  53.                 zgrep ^[^A-Z]
  54.         will find all lines not begining with a capital letter. Note that
  55.         in this case the caret is used in both contexts.
  56.  
  57. Pattern Segments
  58.  
  59. At times is is useful to denote a segment of the search string.  In
  60. ZGrep is a powerful tool to find any combination of file names.
  61.  
  62. \(      denotes the beginning of a segment.
  63. \)      denotes the end of a segment.
  64.  
  65. The best way to understand this usage is by example.
  66.  
  67.     To find all files that begin with the letters A-M
  68.  
  69.     \(.*\) [A-M]
  70.  
  71.     
  72. In this command the use of the '.*' within the first segment is a powerful
  73. construction. It is the same as the DOS '*' wild card. The period followed by
  74. the asterisk means repeat any character any number of times. The files of the
  75. file is the first part of the search. 
  76.  
  77.